package com.wanchuang.shengfubao.view.treeopen;

import android.graphics.Color;
import android.view.View;

import com.chad.library.adapter.base.entity.node.BaseNode;
import com.chad.library.adapter.base.provider.BaseNodeProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.wanchuang.shengfubao.R;
import com.wanchuang.shengfubao.help.GlideHelper;
import com.ruffian.library.widget.RTextView;


import org.jetbrains.annotations.NotNull;

public class RootNodeProvider extends BaseNodeProvider {

    @Override
    public int getItemViewType() {
        return 0;
    }

    @Override
    public int getLayoutId() {
        return R.layout.def_section_head;
    }

    @Override
    public void convert(@NotNull BaseViewHolder helper, @NotNull BaseNode data) {
        // 数据类型需要自己强转
        FirstNode entity = (FirstNode) data;
        helper.setVisible(R.id.line, !entity.isExpanded());
        helper.setText(R.id.tv_word, entity.getPolicyLog().getWord());
        helper.setTextColor(R.id.tv_word,Color.parseColor(entity.getPolicyLog().getColour()));
        GlideHelper.INSTANCE.loadImage(helper.getView(R.id.iv_logo), entity.getPolicyLog().getLogo());
        helper.setText(R.id.tv_title, entity.getPolicyLog().getMemberMsg());
        helper.setText(R.id.tv_time, entity.getPolicyLog().getCreateTime());
        helper.setText(R.id.tv_content, entity.getPolicyLog().getTitle());
        helper.setText(R.id.tv_action_logo, entity.getPolicyLog().getActionMsg());
        if (entity.isExpanded()) {
            helper.setBackgroundResource(R.id.iv_change, R.mipmap.icon_down1);
        } else {
            helper.setBackgroundResource(R.id.iv_change, R.mipmap.icon_right1);
        }
//        if (entity.getPolicyLog().getActionMsg().equals("收到")) {
//
//            helper.<RTextView>getView(R.id.tv_action_logo).getHelper().setTextColorNormal(Color.parseColor("#FF1E79EB"));
//        } else {
//            helper.<RTextView>getView(R.id.tv_action_logo).getHelper().setTextColorNormal(Color.parseColor("#FF53C2A4"));
//        }
        //1显示同意拒接按钮2待伙伴审核3等待钱包pos审核
        switch (entity.getPolicyLog().getStatus()) {
            case "1":
                helper.setGone(R.id.ll_tong_ju, false);
                helper.setGone(R.id.tv_dai, true);
                break;
            case "2":
                helper.setGone(R.id.ll_tong_ju, true);
                helper.setGone(R.id.tv_dai, false);
                helper.setText(R.id.tv_dai, "待伙伴\n审核");
                break;
            case "3":
                helper.setGone(R.id.ll_tong_ju, true);
                helper.setGone(R.id.tv_dai, false);
                helper.setText(R.id.tv_dai, "待" + entity.getPolicyLog().getAppName() + "\n审核");
                break;
        }

    }

    @Override
    public void onClick(@NotNull BaseViewHolder helper, @NotNull View view, BaseNode data, int position) {
        getAdapter().expandOrCollapse(position);
    }
}